package com.zhouyu.exampleThread.threadTest;

/**
 * @Description:线程暴力停止
 */
public class UserPass {
  private String username = "aa";
  private String password = "AA";

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  synchronized public void println(String username, String password){
    this.username = username;
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    this.password = password;
  }

  public static void main(String[] args) throws InterruptedException {
    UserPass userPass = new UserPass();
    Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
        userPass.println("bb","BB");
      }
    });
    thread.start();
    Thread.sleep(500);
    thread.stop();
    System.out.println(userPass.getUsername()+" "+userPass.getPassword());
  }
}
